package sheshen.come.cn.sheshen.feature.adapter;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import org.w3c.dom.Text;

import java.util.List;

import okhttp3.Call;
import sheshen.come.cn.sheshen.MyApplication;
import sheshen.come.cn.sheshen.R;
import sheshen.come.cn.sheshen.base.adpter.MyBaseAdapter;
import sheshen.come.cn.sheshen.base.url.Url;
import sheshen.come.cn.sheshen.been.User;

/**
 * Created by MyPC on 2017/3/7.
 */

public class MineAdapter extends MyBaseAdapter<User.DateBean> {

    public MineAdapter(Context context, List<User.DateBean> data) {
        super(context, data);
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        ViewHolder vh;
        if (view==null){
            view = View.inflate(context, R.layout.item_mine,null);
            vh = new ViewHolder();
            vh.bu = (TextView) view.findViewById(R.id.mine_bu);
            vh.zu = (TextView) view.findViewById(R.id.mine_zu);
            view.setTag(vh);
        }else{
            vh = (ViewHolder) view.getTag();
        }
        final User.DateBean  bean  = data.get(position);
        vh.bu.setText(bean.getWareHouseName());
        vh.zu.setText(bean.getWorkGroupName());
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                OkHttpUtils.post()
                        .url(Url.Job_Group)
                        .addParams("NewLog",bean.getWorkGroupId())
                        .addParams("UserName", MyApplication.getContext().getId())
                        .build()
                        .execute(new MyStringCallback());

            }
        });
        return view;
    }
    public class ViewHolder{
        TextView  zu;
        TextView bu;
    }
    public class MyStringCallback extends StringCallback {

        @Override
        public void onError(Call call, Exception e, int id) {

        }

        @Override
        public void onResponse(String response, int id) {
            Log.e("-------超人--------",response);
        }
    }
}
